package mvp.com.bbc.ui.fragment;

import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;

import mvp.com.bbc.R;
import mvp.com.bbc.base.AppBarStateChangeListener;
import mvp.com.bbc.base.BaseFragment;
import mvp.com.bbc.ui.witget.PullToRefreshLayout;
import mvp.com.bbc.ui.witget.PullableRecyclerViewClever;

/**
 * Created by Administrator on 2017/10/7.
 */

public class ArtListFragment1 extends BaseFragment {
    private static AppBarLayout mAppBarLayout;
    private PullToRefreshLayout mPullToRefreshLayout;
    private PullableRecyclerViewClever mPvp;

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.pullToRefreshLayout);
        mPvp = (PullableRecyclerViewClever) view.findViewById(R.id.community_content_view);
        String type = getArguments().getString("type");
        Log.v("cbf", "type = " + type);
        mAppBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
            @Override
            public void onStateChanged(AppBarLayout appBarLayout, State state) {
                if (state == State.EXPANDED) {
                    //展开状态
                    mPvp.setRefresh(true);
                    mPvp.setLoad(false);
                } else if (state == State.COLLAPSED) {
                    //折叠状态
                    mPvp.setRefresh(false);
                    mPvp.setLoad(true);
                } else {
                    //中间状态
                    mPvp.setRefresh(false);
                    mPvp.setLoad(false);
                }
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_community_list;
    }

    public static Fragment newInstance(String type, AppBarLayout appBarLayou) {
        mAppBarLayout = appBarLayou;
        ArtListFragment1 listFragment1 = new ArtListFragment1();
        Bundle bundle = new Bundle();
        bundle.putString("type", type);
        listFragment1.setArguments(bundle);
        return listFragment1;
    }
}
